﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Game_Admin_Demo.admin
{
    public partial class createGame : System.Web.UI.Page
    {
        DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = dc.danhmucs;
                DropDownList1.DataTextField = "tendm";
                DropDownList1.DataValueField = "madm";
                DropDownList1.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                sanpham sp = new sanpham {
                    tensp=Server.HtmlEncode(TextBoxName.Text),
                    soluong = Convert.ToInt32(TextBoxQuantity.Text.Trim()),
                    hinhanh=TextBoxImage.Text.Trim(),
                    mota=TextBoxDescription.Text,
                    tinhtrang=CheckBox1.Checked,
                    gia=Convert.ToDecimal(TextBoxPrice.Text.Trim()),
                    ngaysx=Convert.ToDateTime(TextBoxDate.Text.Trim()), 
                };

                int madm = Convert.ToInt32(DropDownList1.SelectedValue);
                var dm = dc.danhmucs.FirstOrDefault(z => z.madm == madm);
                dm.sanphams.Add(sp);
               
                dc.SubmitChanges();
                Server.Transfer("Games.aspx");
            }
        }
    }
}